package com.cwiyc.orderonlineback.mapper;

import com.cwiyc.orderonlineback.entity.Order;
import com.cwiyc.orderonlineback.entity.Orderdetail;
import com.cwiyc.orderonlineback.entity.Orderlist;
import com.cwiyc.orderonlineback.entity.Orderlistdetail;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface OrderMapper {

    @Insert("insert into `training`.`order` (orealid,ocreatetime,ototalprice,ostatus,ouid) values (#{orealid},#{ocreatetime},#{ototalprice},#{ostatus},#{ouid})")
    int createorder(String orealid,String ocreatetime, String ototalprice, Integer ostatus, Integer ouid);

    @Insert("insert into `training`.`orderdetail` (odmid,odmcount,odoid) values (#{odmid},#{odmcount},#{odoid})")
    int createOd(Integer odmid, Integer odmcount, Integer odoid);

    @Select("select * from `training`.`orderdetail` where odoid=#{odoid}")
    List<Orderdetail> getorderdetail(Integer odoid);

    @Select("select * from `training`.`order` where orealid=#{orealid}")
    Order getorder(String orealid);

    @Select("select * from ggorder where suid=#{uid}")
    List<Orderlist> getorderlist(Integer uid);

    @Select("select * from ggorderdetail where suid=#{uid}")
    List<Orderlistdetail> getorderlistdetail(Integer uid);

    @Select("select * from usersorder where uid=#{uid}")
    List<Orderlist> userorderlist(Integer uid);

    @Select("select * from usersorderdetail where ouid=#{uid}")
    List<Orderlistdetail> userorderlistdetail(Integer uid);

    @Update("update `training`.`order` set ostatus=#{payload},ofinishtime=#{finishtime} where oid=#{oid}")
    int operateorder(Integer oid, Integer payload, String finishtime);

    @Update("update `training`.`order` set ostatus=#{i} where orealid=#{tradeNo}")
    int updateState(String tradeNo, int i);

}
